# 本章节研究是异常
import traceback
print("------异常---------------")
try:
    f=open("","w",encoding="UTF-8")
    content=f.readlines()
    for item in content:
        print(item.strip())
except:
    print("出现了异常")


print("-------捕获指定的异常-----")
try:
    f=open("","w",encoding="UTF-8")
    content=f.readlines()
    for item in content:
        print(item.strip())
except FileNotFoundError as e :
    print(f"出现了异常:{e}")



print("-------捕获多个异常-----------")
try:
   print(1/0)
except( NameError,ZeroDivisionError) as e :
    print(e)



print("-------捕获所有的异常--------")
try:
    print(name)
except Exception as e:
    print(traceback.format_exc())
    print(type(e))

print("--------捕获异常并输出---------")
try:
    print(name)
except(NameError,ZeroDivisionError) as e:
    print(e)
    print(traceback.format_exc())


print("----异常的else-----------")
try:
    print(4)
except Exception as e:
    print(e)
    print(traceback.format_exc())
else:
    print("如果没有异常要执行的代码....")



print("--------异常的finally--------")
try:
    f=open("",'r',encoding="UTF-8")
    content=f.readlines()
except Exception as e:
    print(e)
    print(traceback.format_exc())
else:
    print("没有异常，真开心....")
finally:
    print("关闭流资源.....")
    f.close()


print("---------异常的传递------------")

def func01():
    print("这是func01开始")
    num=1/0
    print("这是func01的结束")

def func02():
    print("这是func02的开始")
    func01()
    print("这是func02的结束")

def main():
    try:
       func02()
    except Exception as e:
        print(traceback.format_exc())